/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import domain.controller.file.ImageController;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import util.J2meAppHelper;

/**
 *
 * @author Victorino
 */
public class ConfiguracaoForm implements CommandListener, AppForm {

    private List list;
    private Command cmdVoltar = new Command("Voltar", Command.BACK, 0);
    private Command cmdSelect = new Command("Selecionar", Command.ITEM, 1);
    private int BACK_INDEX = -1;

    public ConfiguracaoForm() {


        list = new List("Configurações", List.IMPLICIT);

        this.list.addCommand(cmdVoltar);
        this.list.addCommand(cmdSelect);

        this.list.setCommandListener(this);
    }

    public void commandAction(Command arg0, Displayable arg1) {

        int index = list.getSelectedIndex();
        if (arg0.equals(cmdVoltar) || index == BACK_INDEX) {
            J2meAppHelper.getInstance().changeForm(InicialForm.getInicialForm());
        } else {
            switch (list.getSelectedIndex()) {
                case 0:
                    J2meAppHelper.getInstance().changeForm(new OperadoraForm());
                    break;
                /*case 1:
                    AppHelper.getInstance().changeForm(new ImportarOffForm());
                    break;
                case 3:
                    AppHelper.getInstance().changeForm(new EstadoOnLineForm());
                    break;
                case 4:
                    AppHelper.getInstance().changeForm(new EditarURL());
                    break;
                case 5:
                    AppHelper.getInstance().changeForm(new RemoverCidade());
                    break;
                case 6:
                    final ConfirmForm confirmacaoFrm = new ConfirmForm() {

                        protected void task() {
                            removeBancoDados();
                        }
                    };
                    confirmacaoFrm.setSimCmdAppFrm(this);
                    confirmacaoFrm.setNaoCmdAppFrm(this);

                    AppHelper.getInstance().changeForm(confirmacaoFrm);

                    break;*/
                default:
                    J2meAppHelper.getInstance().changeForm(InicialForm.getInicialForm());
            }
        }

    }

    public Displayable getDisplyable() {
        return list;
    }

    public void initialize(Object parameter) {
        list.deleteAll();

        this.list.append("Operadora", null/*J2meAppHelper.getInstance().getMidlet().getImgOperadora()*/);

        this.list.append("Associar cidade", null/*J2meAppHelper.getInstance().getMidlet().getImgImportOffLine()*/);

        //  this.list.append("Importar on line", AppHelper.getInstance().getMidlet().getImgImportOnline());

        //  this.list.append("Conexão", AppHelper.getInstance().getMidlet().getImgConnection());

        /* Enumeration en = MObjectController.listCidade();
        while (en.hasMoreElements()) {
        this.list.append("Remover Cidade", AppHelper.getInstance().getMidlet().getImgDelete());
        break;
        }
        
        this.list.append("Remover banco de dados", AppHelper.getInstance().getMidlet().getImgDeleteDatabase());

         */

        BACK_INDEX = this.list.append("Voltar", ImageController.getInstance().getVoltarImagem());
    }
}
